
var G_CONFIG = {
	url : {
		addtocart : "/new/d/shops/call/shoppingcartaddto.php",//http://www.12301.cc", //添加到购物车
		jumpToCart : "/new/d/shops/gcartdetail.html", //跳到购物车嶥
		jumpToCart_new_gly : "/new/d/shops/gcartdetail_new_gly.html", //跳到购物车嶥
		jumpToCart_xiu : "/new/d/shops/gcartdetail_xiu.html", //跳到购物车嶥
		jumpToIndex : "/new/d/shops/gtindex.html", //跳到首页
		//jumpToDetail : "http://glyvc.12301.cc/new/d/shops/gdetail.html", //跳到详情页
		jumpToDetail : (function(){
			var domain = document.domain;
			var api = "/new/d/shops/gdetail.html";
			return "http://"+domain + api;
		})(),
		getCartList : "/new/d/shops/call/testshoppingcart.php", //购物车页-获取列表
		cartRemoveItem : "/new/d/shops/call/shoppingcartdelete.php", //购物车页-删除一条item
		successOrderList : "/new/d/shops/call/jh_client.php", //成功订单列表
		newsDetail : "/new/d/shops/call/jh_client.php?action=NoticeDetail", //新闻动态详情
		newsList : "/new/d/shops/call/jh_client.php?action=NoticeList", //新闻动态列表
		//jumpToNewsDetail : "http://glyvc.12301.cc/new/d/shops/gnewsdetail.html", //跳转到新闻动态详情页
		jumpToNewsDetail : (function(){
			var domain = document.domain;
			var api = "/new/d/shops/gnewsdetail.html";
			return "http://" + domain + api;
		})(),
		getProductDetail : "http://yd.12301.cc/custom.php", //获取产品 产品详情&产品列表
		getHot : "http://yd.12301.cc/custom.php"//mx.12301.cc/call/custom.php?method=hot&type=A
	},
	ajaxtimeout : 8 * 1000
};


var G = {
	isEmpty : function(obj){
		for(var i in obj){
			return false;
		}
		return true;
	},
	isPositiveNum : function(count){ //判断文本框输入数值是否为正整数
		count = String(count);
		var type="^[0-9]*[1-9][0-9]*$"; 
        var re = new RegExp(type); 
        if(count.match(re) == null){ 
			return false;
        }
		return true;
	},
	_round2 : function(number,fractionDigits){  
		with(Math){  
			return round(number*pow(10,fractionDigits))/pow(10,fractionDigits);  
		}  
	},
	UA : (function(){
		
		var Sys = {};
        var ua = navigator.userAgent.toLowerCase();
        if(ua.match(/msie/)){ //window.ActiveXObject
            Sys.ie = ua.match(/msie ([\d.]+)/)[1];
		}else if (ua.match(/firefox/)){ //document.getBoxObjectFor
            Sys.firefox = ua.match(/firefox\/([\d.]+)/)[1]
        }else if(ua.match(/chrome/)){//window.MessageEvent && !document.getBoxObjectFor){
            Sys.chrome = ua.match(/chrome\/([\d.]+)/)[1];
        }else if(ua.match(/opera/)){ //window.opera
            Sys.opera = ua.match(/opera.([\d.]+)/)[1]
        }else if (window.openDatabase){
            Sys.safari = ua.match(/version\/([\d.]+)/)[1];
		}	
		return Sys;
		
	})(),
	checkLogin : function(fns){
		fns = fns || {};
		var loaded = fns.logined || function(){};
		var unload = fns.unlogin || function(){};
		var unknow = fns.unknow || function(){};
		var val = $("#iflogin").val();
		if(val == 1){
			loaded();
		}else if(val == 0){
			unload();
		}else{
			unknow();
		}
	},
	DateDiff : function(startTime, endDate){  //sDate1和sDate2是2002-12-18格式
		if(!startTime || !endDate) return false
        var aDate, oDate1, oDate2, iDays;
       /*  aDate = sDate1.split("-");
        oDate1 = new Date(aDate[1] + '-' + aDate[2] + '-' + aDate[0]);  //转换为12-18-2002格式
        aDate = sDate2.split("-");
        oDate2 = new Date(aDate[1] + '-' + aDate[2] + '-' + aDate[0]);
        iDays = parseInt(Math.abs(oDate1 - oDate2) / 1000 / 60 / 60 /24);  //把相差的毫秒数转换为天数 */
		/* oDate1 = new Date(sDate1).getDate().toString();
		oDate2 = new Date(sDate2).getDate().toString();
		iDays = parseInt(Math.abs(oDate1 - oDate2) / 1000 / 60 / 60 /24); 
		return iDays;*/
		var startTime = new Date(Date.parse(startTime.replace(/-/g,"/"))).getTime();
		var endTime = new Date(Date.parse(endDate.replace(/-/g,"/"))).getTime();
		var dates = Math.abs((startTime - endTime))/(1000*60*60*24);     
		return  dates;    
        
	},
	btime : function(stratTime,endTime) {  
		var strat = stratTime.split("-");  
		var end = endTime.split("-");  
		var sdate = new Date(strat[0], strat[1], strat[2]);  
		var edate = new Date(end[0], end[1], end[2]);  
		if (sdate.getTime() > edate.getTime()) {  
			return false;  
		}  
		return true;  
	},
	ToHtmlString : function(htmlStr){
		return toTXT(htmlStr).replace(/\&lt\;br[\&ensp\;|\&emsp\;]*[\/]?\&gt\;|\r\n|\n/g, "<br/>");
		function toTXT(str) {
			var RexStr = /\<|\>|\"|\'|\&|　| /g
			str = str.replace(RexStr,
				function (MatchStr) {
					switch (MatchStr) {
						case "<":
							return "&lt;";
							break;
						case ">":
							return "&gt;";
							break;
						case "\"":
							return "&quot;";
							break;
						case "'":
							return "&#39;";
							break;
						case "&":
							return "&amp;";
							break;
						case " ":
							return "&ensp;";
							break;
						case "　":
							return "&emsp;";
							break;
						default:
							break;
					}
				}
			)
			return str;
		}
	},
	log : function(something){
		if(console && console.log){
			console.log(something)
		}
	},
	ifLogin : function(){
		if($("#iflogin").val()==0) return false;
		return true;
	}
};


//Switch全局插件
;(function(G){
	
	function Switch(container,config){
		this.config = config = $.extend({},Switch.defaults,config);
		this.container = $(container);
		this.slideUl = this.container.find(config.slideBoxCls);
		this.navContainer = this.container.find(config.navContainerCls);
		this.navs = this.navContainer.children();
		this.pannels = this.slideUl.children();
		this.pannelsize = this.pannels.length;
		this.boxWidth = this.pannels.eq(0).outerWidth(true);
		this.prevBtn = this.container.find(config.prevBtnCls);
		this.nextBtn = this.container.find(config.nextBtnCls);
		this.autoPlay = config.autoPlay;
		this.recirle = config.recirle;
		this.curIndex = this.recirle ? 1 : 0;
		this.minIndex = 0;
		this.step = config.step;
		this.maxIndex = this.pannelsize / this.step -1;
		this.timer = null;
		this.time = config.time;
		this.speed = config.speed;
		this.effect = config.effect;
		this.recirle = config.recirle;

		this.triggerType = config.triggerType;
		this.init();
	}
	Switch.prototype = {
		init : function(){
			var that = this;
			var first,last;
			if(this.recirle && this.effect == "slide"){
				first = this.pannels.first();
				last = this.pannels.last()
				this.slideUl.append(first.clone());
				this.slideUl.prepend(last.clone());
				this.pannels = this.slideUl.children();
				this.pannelsize = this.pannels.length;
				this.maxIndex = this.pannelsize / this.step -1;
				this.slideUl.css({left:-this.step})
			}
			if(this.effect == "slide"){
				var w = 0;
				this.pannels.each(function(index,li){
					w += $(this).outerWidth(true);
				})
				this.slideUl.width(w);
			}else if(this.effect == "fade"){
				this.pannels.css({"zIndex":0,"opacity":0}).removeClass("show").eq(0).css({"zIndex":0,"opacity":1}).addClass("show");
			}
			if(this.autoPlay){
				this._setInterval();
			}
			this.prevBtn.on("click",function(e){
				clearInterval(that.timer);
				that.prev();
				return false;
			})
			this.nextBtn.on("click",function(e){
				clearInterval(that.timer);
				that.next();
				return false;
			})
			this.navContainer.on(that.triggerType,"li",function(e){
				var target = $(e.currentTarget);
				that._triggerHandler(target);
				return false;
			})
		},
		_go : function(index){
			var that = this;
			var curIndex = this.curIndex;
			var slideUl = this.slideUl;
			var step = this.step;
			var boxWidth = this.boxWidth;
			var effect = this.effect;
			var recirle = this.recirle;
			var slideUl = this.slideUl;
			var pannels = this.pannels;
			var pannelsize = this.pannelsize;
			var maxIndex = this.maxIndex;
			var minIndex = this.minIndex;
			this.navs.eq(index).addClass("active").siblings().removeClass("active");
			this.config.onSwitchBefore(curIndex,index);
			if(effect == "slide"){
				slideUl.stop().animate({left:-1*step*boxWidth*index},that.speed,function(){
					that.curIndex = index;
					if(recirle && index == maxIndex && effect == "slide"){
						that.curIndex = 1;
						slideUl.css({left:-step*boxWidth})
					}else if(recirle && index == minIndex && effect == "slide"){
						that.curIndex = maxIndex-1;
						slideUl.css({left:-step*boxWidth*that.curIndex})
					}
					that.config.onSwitchAfter(that.curIndex);
				});
			}else if(effect == "fade"){
				pannels.eq(index).css("zIndex",1).siblings().css("zIndex",0);
				pannels.eq(index).animate({opacity:1},that.speed,function(){
					pannels.removeClass("show").eq(index).addClass("show")
					that.curIndex = index;
					that.config.onSwitchAfter(that.curIndex);
				})
				pannels.filter(function(){
					return $(this).hasClass("show");
				}).stop().animate({opacity:0},that.speed,function(){})
			}
			
		},
		_triggerHandler : function(target){
			var that = this;
			clearTimeout(that.timer);
			that.slideUl.stop();
			var index = that.navs.index(target);
			if(index < 0) return false;
			that.timer = setTimeout(function(){
				that._go(index);
				that.navs.eq(index).addClass("active").siblings().removeClass("active");
			},200)
		},
		_setInterval : function(){
			var that = this;
			clearTimeout(that.timer);
			this.timer = setInterval(function(){
				that.next()
			},that.time);
		},
		next : function(){
			var curIndex = this.curIndex;
			var pannelsize = this.pannelsize;
			var maxIndex = this.maxIndex;
			var recirle = this.recirle;
			var index = 0;
			if(curIndex == maxIndex){
				index = 0;
			}else{
				index = curIndex + 1;
			}
			this._go(index);
		},
		prev : function(){
			var curIndex = this.curIndex;
			var pannelsize = this.pannelsize;
			var minIndex = this.minIndex;
			var maxIndex = this.maxIndex;
			var recirle = this.recirle;
			var index = 0;
			if(curIndex == minIndex){
				index = maxIndex;
			}else{
				index = curIndex - 1;
			}
			this._go(index);
		}
	}
	Switch.defaults = {
		"time" : "4000", //间隔4s
		"speed" : "400", //速度 
		"autoPlay" : true,
		"slideBoxCls" : "",
		"navContainerCls" : "",
		"prevBtnCls" : "",
		"nextBtnCls" : "",
		"effect" : "slide",
		"step" : 1,
		"triggerType" : "mouseover", //"mouseover" || "click"
		"recirle" : false, //循环
		"onSwitchBefore" : function(){},
		"onSwitchAfter" : function(){}
	};
	
	G.Switch = Switch;
	
})(G)

//图片加载器 
;(function(G){
	var emptyFn = new Function();
	var Imgs = {};
	function ImgLoador(config){
		this.config = $.extend({},ImgLoador.defaults,config);
		
	}
	ImgLoador.defaults = {
	
	};
	ImgLoador.prototype = {
		getImg : function(imgurl){
			return Imgs[imgurl];
		},
		getImgWidth : function(index){
		
		},
		getImgHeight : function(index){
		
		},
		load : function(imgurl,fn){
			fn = typeof fn === "function" ? fn : emptyFn; 
			var img = new Image();
			img.src = imgurl;
			if(img.complete && Imgs[imgurl]){
				fn(img);
				return false;
			}
			img.onload = function(){
				fn(img);
			}
			Imgs[imgurl] = img;
		},
		remove : function(index){
		
		},
		getSize : function(){
		
		}
	}
	
	G.ImgLoador = ImgLoador;
	
})(G);

//登录
;(function(G){
	
	var Login = {};
	var Register = {};
	var screenWidth = 0;
	var screenHeight = 0;
	var hasBindevent = false;
	var bgColor = "#000";
	var opacity = 0.4;
	var loginPop;
	var mask;
	var main;
	var defaults = {
		bgColor : "#000",
		opacity : 0.4,
		beforeOpen : function(){},
		afterOpen : function(){},
		beforeClose : function(){},
		afterClose : function(){}
	}
	var userInpInt = "请输入11位手机号";
	var pwInpInt = "请输入6位数密码";
	var mobReg = /1[3-8]+\d{9}/; //验证11位手机号
	Login.init = function(){
		screenWidth = $(window).width();
		screenHeight = $(window).height();
		loginPop = $("#gLoginPopW");
		mask = loginPop.find(".gloginMask");
		main = loginPop.find(".gloginMain");
		var slideUl = main.find(".loginSlideUl");
		var step = slideUl.children().first().width();
		main.on("click",".gloginPopClose",function(){
			Login.close();
		}).on("click",".loginW .botW a.singup",function(e){
			slideUl.animate({left:-step});
		}).on("click",".singupW .botW a.sloginBtn",function(e){
			slideUl.animate({left:0});
		}).on("click","#glogin_loginBtn",function(e){
			var userInp = $("#glogin_userInp");
			var passwordInp = $("#glogin_passwordInp");
			var name = $.trim(userInp.val());
			var password = $.trim(passwordInp.val());
			login(name,password);
			return false;
		}).on("keydown",function(e){
			var keyCode = e.keyCode;
			var target = $(e.target);
			if(target.hasClass("gloginInp")){
				target.parents(".glgInpCtrol").next(".errorTip").hide();
			}
			if(keyCode == 13){
				var name = $("#glogin_userInp").val();
				var password = $("#glogin_passwordInp").val();
				name = $.trim(name);
				password = $.trim(password);
				login(name,password);
			}
			if(keyCode == 9 && !target.hasClass("tabInp")){
				return false;
			}
		}).on("blur","input.varifyInp",function(e){
			var t = $(this);
			if(!t.val()){
				if(t.hasClass("usernameInp")){
					t.val(userInpInt)
				}else if(t.hasClass("passwordInp")){
					
				}else if(t.hasClass("telInp")){
					t.val(userInpInt)
				}
			}
		}).on("focus","input.varifyInp",function(e){
			var t = $(this);
			var tv = t.val();
			if(t.hasClass("usernameInp") && tv == userInpInt){
				t.val("");
			}else if(t.hasClass("passwordInp")){
				
			}else if(t.hasClass("telInp") && tv == userInpInt){
				t.val("")
			}
		}).on("click","#glogin_getmaCode",function(e){
			getmaCode();
			return false;
		}).on("click","#glogin_singupBtn",function(e){
			singin();
			return false;
		})
		main.css({
			top : -main.height()-10,
			left : (screenWidth-main.width()) / 2
		})
		//点击弹出登录框
		$("#loginStart").on("click",function(e){
			Login.open();
			return false;
		})
		//点击退出登录
		$("#gToplogout").on("click",function(e){
			$.ajax({
				"url":"../call/handle.php",
				"data":{"from":"logout"},
				"dataType":"json",
				"success":function(data){
					window.location.reload();
					window.location.href="gtindex.html";
					//window.location.href="http://mx.12301.cc/client/home.html";
				},
				"error":function(){
					window.location.href="gtindex.html";
					//window.location.href="http://mx.12301.cc/client/home.html";
				}
			});
			return false;
		})
		
		var userInp = $("#glogin_userInp");
		var telInp = $("#glogin_telInp");
		userInp.val(userInpInt);
		telInp.val(userInpInt);
	}
	Login.open = function(config){
		config = config || {};
		for(var i in defaults){
			if(typeof config[i] === "undefined"){
				config[i] = defaults[i];
			}
		}
		config.beforeOpen();
		refresh();
		mask.css({zIndex:10000,backgroundColor:config.bgColor,opacity:config.opacity}).fadeIn(function(){
			main.show().animate({top:(screenHeight-main.height())/2},400,function(){
				config.afterOpen();
			})
		});
	}
	Login.sigin = function(){
		Login.open();
		$("#loginSlideUl").css("left","-320px");
	}
	Login.close = function(config){
		config = config || {};
		for(var i in defaults){
			if(typeof config[i] === "undefined"){
				config[i] = defaults[i];
			}
		}
		config.beforeClose();
		main.animate({top:-main.height()-10},400,function(){
			config.afterClose();
		})
		mask.fadeOut();
	}
	//登录
	function login(name,password,json){
		var loginBtn = $("#glogin_loginBtn");
		if(loginBtn.hasClass("loading")){
			alert("正在登录，请勿重复登录")
		}
		var nerror = $("#glogin_userInp").parents(".glgInpCtrol").next();
		var werror = $("#glogin_passwordInp").parents(".glgInpCtrol").next();
		if(!name){
			nerror.text("*请输入用户名(手机号)").show();
			return;
		}
		if(name.length !== 11 || !mobReg.test(name)){
			nerror.text("*请输入有效手机号").show();
			return;
		}
		if(!password){
			werror.text("*请输入密码").show();
			return;
		}
		// if(password.length !== 6){
			// werror.text("*请输入6位数密码").show();
			// return;
		// }
		nerror.hide();
		werror.hide();
		json = json || {};
		var success = json.success || function(){}; //成功
		var unexist = json.unexist || function(){}; //帐号未注册
		var untrue = json.untrue || function(){};  //密码
		var timeout = json.timeout || function(){}; //超时
		var error = json.error || function(){};   //错误
		loginBtn.addClass("loading");
		$.ajax({
			url : "call/loginProcess.php",
			type : "POST",
			dataType : "JSON",
			timeout : 10 * 1000,
			data : {
				action : "login_t",
				username : name,
				password : password
			},
			success : function(res){
				if(res && res.code){
					if(res.code == 100){
						window.location.reload();
						success(res);
					}else if(res.code == 101){ //无此帐号
						alert("此帐号不存在")
						unexist();
					}else if(res.code == 102){ //密码错误
						alert("抱歉，您输入的密码有误！")
						untrue();
					}
				}else{
					alert("服务器出错")
					error();
				}
			},
			error : function(xhr,text){
				if(text == "timeout"){
					alert("登录超时，请稍后重试")
					timeout();
				}else{
					alert("服务器出错")
					error();
				}
			},
			complete : function(){
				loginBtn.removeClass("loading")
			}
		})
	}
	//注册
	function singin(){
		var code = $("#glogin_macodeInp").val();
		var mobile = $("#glogin_telInp").val();
		var signBtn = $("#glogin_singupBtn");
		if(signBtn.hasClass("loading")) return false;
		code = $.trim(code);
		mobile = $.trim(mobile);
		if(!mobile){
			alert("*请输入手机号");
			return false;
		}
		if(mobile.length !== 11 || !mobReg.test(mobile)){
			alert("*请输入有效手机号");
			return false;
		}
		if(!code){
			alert("请输入验证码");
			return false;
		}
		$("#glogin_singupBtn").addClass("loading");
		$.ajax({
			url : "call/register.php",
			type : "POST",
			dataType : "JSON",
			data : {
				action : "register",
				mobile : mobile,
				valiCode : code
			},
			success : function(res){
				if(res && res.code){
					if(res.code == 100){ //成功
						alert("注册成功！");
						$("#loginStart").text($("#glogin_telInp").val());
						window.location.reload();
					}else if(res.code == 101){ //帐号已注册
						alert("此帐号已被注册");
					}else if(res.code == 103){ //验证码不正确
						alert("验证码不正确");
					}else{
						alert("注册失败，请稍后重试");
					}
				}else{ //出错
					alert("注册失败，请稍后重试");
				}
			},
			error : function(){
				alert("注册失败，请稍后重试");
			},
			complete : function(){
				signBtn.removeClass("loading");
			}
		})
	}
	//获取验证码
	function getmaCode(){
		var getBtn = $("#glogin_getmaCode");
		var telInp = $("#glogin_telInp");
		var tel = $.trim(telInp.val());
		if(getBtn.hasClass("loading")) return false;
		var timer = null;
		var time = 60;
		if(!tel){
			alert("*请输入手机号");
			return;
		}
		if(tel.length !== 11 || !mobReg.test(tel)){
			alert("*请输入有效手机号");
			return;
		}
		getBtn.addClass("loading").val("正在获取...");
		$.ajax({
			url : "call/register.php",
			type : "POST",
			dataType : "JSON",
			data : {
				action : "sendCode",
				mobile : tel
			},
			success : function(res){
				if(res && res.code){
					if(res.code == 100){ //成功
						_reGet();
					}else if(res.code == 102){ //手机号已被注册过
						alert("此手机号已被注册过");
						getBtn.val("获取验证码");
						getBtn.removeClass("loading");
					}else{ //失败
						_reGet();
						alert("获取验证码失败,60s后请重新获取");
					}
				}else{ //出错
					_reGet();
					alert("获取验证码时服务器出错，60s后请重新获取");
				}
			},
			error : function(xhr,text){ //出错
				_reGet();
				alert("获取验证码时服务器出错，60s后请重新获取");
			}
		})
		function _reGet(){
			timer = setInterval(function(){
				if(time==0){
					getBtn.val("获取验证码");
					getBtn.removeClass("loading");
					clearInterval(timer);
					return;
				}
				time--;
				getBtn.val(time+"秒后重新获取");
			},1000)
		}
	}
	function refresh(){
		main.find(".gloginInp").val("");
		$("#glogin_userInp").val(userInpInt);
		$("#glogin_telInp").val(userInpInt);
		main.find(".errorTip").hide();
		main.find(".loginSlideUl").css({left:0})
	}
	
	
	
	G.Login = Login;
	
})(G);

//循环滚动成功订单
;(function(){
	var SucOrderNews = {};
	var INTERVAL_TIME = 5 * 60 * 1000;
	var newsSlider = null;
	var container = null;
	function ajax(fns){
		fns = fns || {};
		var url = G_CONFIG.url.successOrderList;
		var fn = new Function();
		var loading = fns.loading || fn;
		var removeLoading = fns.removeLoading || fn;
		var success = fns.success || fn;
		var empty = fns.empty || fn;
		var timeout = fns.timeout || fn;
		var ttimeout = G_CONFIG.ajaxtimeout;
		var error = fns.error || fn;
		loading();
		$.ajax({
			url : url,
			type : "GET",
			dataType : "JSON",
			timeout : ttimeout,
			data : {
				action : "RealTimeOrder"
			},
			success : function(res){
				removeLoading();
				if(res && res.length){
					success(res);
				}else{
					empty(res);
				}
			},
			error : function(xhr,txt){
				removeLoading();
				if(txt == "timeout"){
					timeout();
				}else{
					error();
				}
			}
		})
	}

	function initGet(){ //初始化请求
		//var wrap = $("#sucOrderList");
		var listUl = container.find(".listUl");
		var loadingTxt = '<li class="loading statusTxt">加载中...</li>';
		var emptyTxt = '<li class="empty statusTxt">返回数据为空...</li>';
		var timeoutTxt = '<li class="timeout statusTxt">请求超时，请<a class="retryBtn" onclick="G.SucOrderNews.init()" style="margin-left:3px;" href="###">重试</a></li>';
		var errorTxt = '<li class="error statusTxt">请求出错，请<a class="retryBtn" onclick="G.SucOrderNews.init()" style="margin-left:3px;" href="###">重试</a></li>';
		ajax({
			loading : function(){
				listUl.html(loadingTxt);
			},
			removeLoading : function(){
				listUl.html("");
				_setInterval();
			},
			success : function(res){
				var html = build(res);
				listUl.html(html);
				setTimeout(function(){
					var stage = container.find(".conWrap");
					newsSlider = new S(stage);
				},0)
			},
			empty : function(){
				listUl.html(emptyTxt);
			},
			timeout : function(){
				listUl.html(timeoutTxt);
			},
			error : function(){
				listUl.html(errorTxt);
			}
		})
	}
	function update(){
		var listUl = container.find(".listUl");
		ajax({
			success : function(res){
				listUl.html(build(res));
				setTimeout(function(){
					newsSlider.refresh();
				},0)
			}
		})
	}
	function _setInterval(){
		setInterval(update,INTERVAL_TIME);
	}
	function build(res){
		var html = "";
		for(var i in res){
			var item = res[i];
			html += '<li><div class="liCon"><span class="t">'+item["ordertime"]+'</span><span class="user">'+item["ordername"]+'</span><span class="suc">成功预订</span><a href="'+G_CONFIG.url.jumpToDetail+'?lid='+item["lid"]+'" target="_blank" class="pn">'+item["ltitle"]+' '+item["ttitle"]+'</a></span></div></li>';
		}
		return html;
	}
	var S = (function(){

		function newsSlider(container,config){
			var config = this.config = $.extend({},newsSlider.defaults,config);
			this.container = container;
			this.listUl = container.children();
			this.step = config.step || this.listUl.children().first().outerHeight(true);
			this.slideSpeed = config.speed;
			this.slideInterval = config.interval;
			this.dir = config.dir.toLowerCase();
			this.timer = null;
			this.init();
		}
		newsSlider.defaults = {
			dir : "v",   //方向  h-横向   v-竖向
			speed : 400, //滚动速度
			interval : 2 //滚动间隔 单位秒
		};
		newsSlider.prototype = {
			init : function(){
				var self = this;
				this.container.hover(function(){
					self.stop();
				},function(){
					self.begin();
				})
				this.timer = setTimeout(function(){
					self.anim();
				},this.slideInterval*1000);
			},
			anim : function(){
				var self = this;
				var dir = this.dir == "v" ? "top" : "left";
				var step = this.step;
				var slideInterval = this.slideInterval;
				var speed = this.slideSpeed;
				var listUl = this.listUl;
				var css = {};
				css[dir] = -1*step;
				listUl.stop().animate(css,speed,function(){
					listUl.css("top",0).children().first().appendTo(listUl);
					clearTimeout(self.timer);
					self.timer = setTimeout(function(){
						self.anim();
					},slideInterval*1000);
				})
			},
			refresh : function(){
				var self = this;
				var css = this.dir == "v" ? {top:0} : {left:0};
				this.listUl = this.container.children();
				this.listUl.css(css).stop();
				this.timer = setTimeout(function(){
					self.anim();
				},this.slideInterval*1000)
			},
			stop : function(){
				this.listUl.stop();
				clearTimeout(this.timer);
			},
			begin : function(){
				var self = this;
				this.timer = setTimeout(function(){
					self.anim();
				},1000)
			}
		}

		return newsSlider;

	})();

	SucOrderNews.init = function(wrap){
		if(typeof wrap == "string"){
			container = $(wrap);
		}else{
			container = $("#sucOrderList");
		}
		initGet();
	}

	G.SucOrderNews = SucOrderNews;

})();


//新闻公告动态
;(function(){
	var News = {};
	var container = null;
	function getDetail(id,json){
		if(!id) return false;
		var url = G_CONFIG.url.newsDetail;
		var fn = new Function();
		var loading = json.loading || fn;
		var removeLoading = json.removeLoading || fn;
		var success = json.success || fn;
		var empty = json.empty || fn;
		var timeout = json.timeout || fn;
		var ttimeout = G_CONFIG.ajaxtimeout;
		var error = json.error || fn;
		loading();
		$.ajax({
			url : url,
			type : "GET",
			dataType : "JSON",
			timeout : ttimeout,
			data : { id : id },
			success : function(res){
				removeLoading();
				if(res){
					success(res);
				}else{
					empty(res);
				}
			},
			error : function(xhr,txt){
				removeLoading();
				if(txt == "timeout"){
					timeout();
				}else{
					error();
				}
			}
		})
	}
	function ajaxList(json){
		var json = json || {};
		var url = G_CONFIG.url.newsList;
		var fn = new Function();
		var loading = json.loading || fn;
		var removeLoading = json.removeLoading || fn;
		var success = json.success || fn;
		var empty = json.empty || fn;
		var timeout = json.timeout || fn;
		var ttimeout = G_CONFIG.ajaxtimeout;
		var error = json.error || fn;
		loading();
		$.ajax({
			url : url,
			type : "GET",
			dataType : "JSON",
			timeout : ttimeout,
			success : function(res){
				removeLoading();
				if(res && res.length){
					success(res);
				}else{
					empty(res);
				}
			},
			error : function(xhr,txt){
				removeLoading();
				if(txt == "timeout"){
					timeout();
				}else{
					error();
				}
			}
		})
	}
	function getList(callback){ //初始化请求列表
		//var wrap = $("#sucOrderList");
		var listUl = container.find(".listUl");
		var loadingTxt = '<li class="loading statusTxt">加载中...</li>';
		var emptyTxt = '<li class="empty statusTxt">返回数据为空...</li>';
		var timeoutTxt = '<li class="timeout statusTxt">请求超时，请<a class="retryBtn" style="margin-left:3px;" href="#">重试</a></li>';
		var errorTxt = '<li class="error statusTxt">请求出错，请<a class="retryBtn" style="margin-left:3px;" href="#">重试</a></li>';
		ajaxList({
			loading : function(){
				listUl.html(loadingTxt);
			},
			removeLoading : function(){
				listUl.html("");
			},
			success : function(res){
				var html = buildList(res);
				listUl.html(html);
				callback && callback(res);
				setTimeout(function(){
					//var stage = $("#newsSlideStage");
					//var listUl = $("#newsSlideListUl");
					var stage = container.find(".conWrap");
					var listUl = container.find(".listUl");
					if(listUl.height()>stage.height()){
						new S($("#newsSlideStage"));
					}
				},0)
			},
			empty : function(){
				listUl.html(emptyTxt);
			},
			timeout : function(){
				listUl.html(timeoutTxt);
			},
			error : function(){
				listUl.html(errorTxt);
			}
		})
	}
	function buildList(res){
		var html = "";
		for(var i in res){
			var item = res[i];
			html += '<li><div class="liCon"><a class="title ggellipsis" href="'+G_CONFIG.url.jumpToNewsDetail+'?id='+item["id"]+'" class="pn">'+item["title"]+'</a><span class="t">'+item["btime"]+'</span></span></div></li>';
		}
		return html;
	}
	var S = (function(){

		function newsSlider(container,config){
			var config = this.config = $.extend({},newsSlider.defaults,config);
			this.container = container;
			this.listUl = container.children();
			this.step = config.step || this.listUl.children().first().outerHeight(true);
			this.slideSpeed = config.speed;
			this.slideInterval = config.interval;
			this.dir = config.dir.toLowerCase();
			this.timer = null;
			this.init();
		}
		newsSlider.defaults = {
			dir : "v",   //方向  h-横向   v-竖向
			speed : 400, //滚动速度
			interval : 2 //滚动间隔 单位秒
		};
		newsSlider.prototype = {
			init : function(){
				var self = this;
				this.container.hover(function(){
					self.stop();
				},function(){
					self.begin();
				})
				this.timer = setTimeout(function(){
					self.anim();
				},this.slideInterval*1000);
			},
			anim : function(){
				var self = this;
				var dir = this.dir == "v" ? "top" : "left";
				var step = this.step;
				var slideInterval = this.slideInterval;
				var speed = this.slideSpeed;
				var listUl = this.listUl;
				var css = {};
				css[dir] = -1*step;
				listUl.stop().animate(css,speed,function(){
					listUl.css("top",0).children().first().appendTo(listUl);
					clearTimeout(self.timer);
					self.timer = setTimeout(function(){
						self.anim();
					},slideInterval*1000);
				})
			},
			refresh : function(){
				var self = this;
				var css = this.dir == "v" ? {top:0} : {left:0};
				this.listUl = this.container.children();
				this.listUl.css(css).stop();
				this.timer = setTimeout(function(){
					self.anim();
				},this.slideInterval*1000)
			},
			stop : function(){
				this.listUl.stop();
				clearTimeout(this.timer);
			},
			begin : function(){
				var self = this;
				this.timer = setTimeout(function(){
					self.anim();
				},1000)
			}
		}

		return newsSlider;

	})();
	News.getDetail = getDetail;
	News.init = function(wrap){
		if(typeof wrap == "string"){
			container = $(wrap);
		}else{
			container = $("#sucOrderList");
		}
		getList();
	}
	G.News = News;

})();






